<?php

namespace app\common\common;

use app\common\library\Auth;
use app\common\service\common\PoiService;
use think\Exception;
use think\Request;
use Throwable;

class PerServer
{
    /**
     * @var PerServer
     */
    private static $_obj;
    /**
     * 权限Auth
     * @var Auth
     */
    protected $auth = null;


    public function __construct(Request $request = null)
    {
        // 控制器初始化
        $this->auth = Auth::instance();
    }

    public static function getInstance()
    {

        if (empty(static::$_obj)) {
            static::$_obj = new static();
        }

        return static::$_obj;
    }


    /**
     * @param null $auth
     * @return false
     *
     * 是否有查看的权限
     * 1增  2删 3查 4改
     */
    public function isAuth($auth = null){

        $user = $this->auth->getUserinfo();
        $userPer = Common::$userPer;
        if(!isset($userPer[$user['user_permissions']])){
            return false;
        }
        $userPerArr = $userPer[$user['user_permissions']];
        return in_array($auth,$userPerArr) ? true : false;

    }

}
